﻿Partial Public Class FrmPropertyBill
#Region "离开项目1时的事件"
    Private Sub FItem1Box_Leave(sender As Object, e As EventArgs) Handles FItem1Box.Leave
        '--检查是否已存在项目

        If FOpenType = "View" Then
            Return
        End If
        Dim s As Integer = FItem1Box.FindStringExact(FItem1Box.Text.Trim)
        If s > -1 Then
            '-存在
            Dim FIInfo As New BServer.FBaseProperty
            FItem1Box.SelectedIndex = s
            FIInfo.id = FItem1Box.SelectedValue
            If SControl._BILL_Prop_GetItemInfo(UInfo.FSession, FIInfo.id, "", FIInfo, "") = False Then
                Return
            End If
            FQty1Box.Value = FIInfo.FQty
            FPrice1Box.Value = FIInfo.FPrice
        End If
    End Sub
#End Region

#Region "离开项目2时的事件"
    Private Sub FItem2Box_Leave(sender As Object, e As EventArgs) Handles FItem2Box.Leave
        '--检查是否已存在项目
        If FOpenType = "View" Then
            Return
        End If
        Dim s As Integer = FItem2Box.FindStringExact(FItem2Box.Text.Trim)
        If s > -1 Then
            '-存在
            Dim FIInfo As New BServer.FBaseProperty
            FItem2Box.SelectedIndex = s
            FIInfo.id = FItem2Box.SelectedValue
            If SControl._BILL_Prop_GetItemInfo(UInfo.FSession, FIInfo.id, "", FIInfo, "") = False Then
                Return
            End If
            FQty2Box.Value = FIInfo.FQty
            FPrice2Box.Value = FIInfo.FPrice
        End If
    End Sub
#End Region

#Region "离开项目3时的事件"
    Private Sub FItem3Box_Leave(sender As Object, e As EventArgs) Handles FItem3Box.Leave
        '--检查是否已存在项目
        If FOpenType = "View" Then
            Return
        End If
        Dim s As Integer = FItem3Box.FindStringExact(FItem3Box.Text.Trim)
        If s > -1 Then
            '-存在
            Dim FIInfo As New BServer.FBaseProperty
            FItem3Box.SelectedIndex = s
            FIInfo.id = FItem3Box.SelectedValue
            If SControl._BILL_Prop_GetItemInfo(UInfo.FSession, FIInfo.id, "", FIInfo, "") = False Then
                Return
            End If
            FQty3Box.Value = FIInfo.FQty
            FPrice3Box.Value = FIInfo.FPrice
        End If
    End Sub
#End Region

#Region "离开项目4时的事件"
    Private Sub FItem4Box_Leave(sender As Object, e As EventArgs) Handles FItem4Box.Leave
        '--检查是否已存在项目
        If FOpenType = "View" Then
            Return
        End If
        Dim s As Integer = FItem4Box.FindStringExact(FItem4Box.Text.Trim)
        If s > -1 Then
            '-存在
            Dim FIInfo As New BServer.FBaseProperty
            FItem4Box.SelectedIndex = s
            FIInfo.id = FItem4Box.SelectedValue
            If SControl._BILL_Prop_GetItemInfo(UInfo.FSession, FIInfo.id, "", FIInfo, "") = False Then
                Return
            End If
            FQty4Box.Value = FIInfo.FQty
            FPrice4Box.Value = FIInfo.FPrice
        End If
    End Sub
#End Region

#Region "所有触发计算类过程"
    Private Sub FItem1Box_TextChanged(sender As Object, e As EventArgs) Handles FItem1Box.TextChanged
        If FOpenType = "View" Then
            Return
        End If
        If FItem1Box.Text.Trim = String.Empty Then
            Return
        End If
        If FSDate1Box.Value = Nothing Then
            FSDate1Box.Value = Now
        End If
        If FEDate1Box.Value = Nothing Then
            FEDate1Box.Value = Now
        End If
    End Sub

    Private Sub FItem2Box_TextChanged(sender As Object, e As EventArgs) Handles FItem2Box.TextChanged
        If FOpenType = "View" Then
            Return
        End If
        If FItem2Box.Text.Trim = String.Empty Then
            Return
        End If
        If FSDate2Box.Value = Nothing Then
            FSDate2Box.Value = Now
        End If
        If FEDate2Box.Value = Nothing Then
            FEDate2Box.Value = Now
        End If
    End Sub

    Private Sub FItem3Box_TextChanged(sender As Object, e As EventArgs) Handles FItem3Box.TextChanged
        If FOpenType = "View" Then
            Return
        End If
        If FItem3Box.Text.Trim = String.Empty Then
            Return
        End If
        If FSDate3Box.Value = Nothing Then
            FSDate3Box.Value = Now
        End If
        If FEDate3Box.Value = Nothing Then
            FEDate3Box.Value = Now
        End If
    End Sub

    Private Sub FItem4Box_TextChanged(sender As Object, e As EventArgs) Handles FItem4Box.TextChanged
        If FOpenType = "View" Then
            Return
        End If
        If FItem4Box.Text.Trim = String.Empty Then
            Return
        End If
        If FSDate4Box.Value = Nothing Then
            FSDate4Box.Value = Now
        End If
        If FEDate4Box.Value = Nothing Then
            FEDate4Box.Value = Now
        End If
    End Sub

    Private Sub FSDate1Box_ValueChanged(sender As Object, e As EventArgs) Handles FSDate1Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        If FSDate1Box.Value = Nothing Or FEDate1Box.Value = Nothing Then
            Return
        End If
        Try
            FDays1Box.Value = 1 + DateDiff(DateInterval.Day, FSDate1Box.Value.Date, FEDate1Box.Value.Date)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FEDate1Box_ValueChanged(sender As Object, e As EventArgs) Handles FEDate1Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        If FSDate1Box.Value = Nothing Or FEDate1Box.Value = Nothing Then
            Return
        End If
        Try
            FDays1Box.Value = 1 + DateDiff(DateInterval.Day, FSDate1Box.Value.Date, FEDate1Box.Value.Date)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FSDate2Box_ValueChanged(sender As Object, e As EventArgs) Handles FSDate2Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        If FSDate2Box.Value = Nothing Or FEDate2Box.Value = Nothing Then
            Return
        End If
        Try
            FDays2Box.Value = 1 + DateDiff(DateInterval.Day, FSDate2Box.Value.Date, FEDate2Box.Value.Date)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FEDate2Box_ValueChanged(sender As Object, e As EventArgs) Handles FEDate2Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        If FSDate2Box.Value = Nothing Or FEDate2Box.Value = Nothing Then
            Return
        End If
        Try
            FDays2Box.Value = 1 + DateDiff(DateInterval.Day, FSDate2Box.Value.Date, FEDate2Box.Value.Date)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FSDate3Box_ValueChanged(sender As Object, e As EventArgs) Handles FSDate3Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        If FSDate3Box.Value = Nothing Or FEDate3Box.Value = Nothing Then
            Return
        End If
        Try
            FDays3Box.Value = 1 + DateDiff(DateInterval.Day, FSDate3Box.Value.Date, FEDate3Box.Value.Date)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FEDate3Box_ValueChanged(sender As Object, e As EventArgs) Handles FEDate3Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        If FSDate3Box.Value = Nothing Or FEDate3Box.Value = Nothing Then
            Return
        End If
        Try
            FDays3Box.Value = 1 + DateDiff(DateInterval.Day, FSDate3Box.Value.Date, FEDate3Box.Value.Date)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FSDate4Box_ValueChanged(sender As Object, e As EventArgs) Handles FSDate4Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        If FSDate4Box.Value = Nothing Or FEDate4Box.Value = Nothing Then
            Return
        End If
        Try
            FDays4Box.Value = 1 + DateDiff(DateInterval.Day, FSDate4Box.Value.Date, FEDate4Box.Value.Date)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FEDate4Box_ValueChanged(sender As Object, e As EventArgs) Handles FEDate4Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        If FSDate4Box.Value = Nothing Or FEDate4Box.Value = Nothing Then
            Return
        End If
        Try
            FDays4Box.Value = 1 + DateDiff(DateInterval.Day, FSDate4Box.Value.Date, FEDate4Box.Value.Date)
        Catch ex As Exception

        End Try

    End Sub

    Private Sub FQty1Box_ValueChanged(sender As Object, e As EventArgs) Handles FQty1Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc1Box.Value = FQty1Box.Value * FPrice1Box.Value * FDays1Box.Value
            '--总金额
            FAmountLabel.Text = CInt(FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FPrice1Box_ValueChanged(sender As Object, e As EventArgs) Handles FPrice1Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc1Box.Value = FQty1Box.Value * FPrice1Box.Value * FDays1Box.Value
            '--总金额
            FAmountLabel.Text = CInt(FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FDays1Box_ValueChanged(sender As Object, e As EventArgs) Handles FDays1Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc1Box.Value = FQty1Box.Value * FPrice1Box.Value * FDays1Box.Value
            '--总金额
            FAmountLabel.Text = CInt(FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
        
    End Sub

    Private Sub FQty2Box_ValueChanged(sender As Object, e As EventArgs) Handles FQty2Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc2Box.Value = FQty2Box.Value * FPrice2Box.Value * FDays2Box.Value
            '--总金额
            FAmountLabel.Text = CInt((FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value))
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FPrice2Box_ValueChanged(sender As Object, e As EventArgs) Handles FPrice2Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc2Box.Value = FQty2Box.Value * FPrice2Box.Value * FDays2Box.Value
            '--总金额
            FAmountLabel.Text = CInt(FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FDays2Box_ValueChanged(sender As Object, e As EventArgs) Handles FDays2Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc2Box.Value = FQty2Box.Value * FPrice2Box.Value * FDays2Box.Value
            '--总金额
            FAmountLabel.Text = CInt(FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FQty3Box_ValueChanged(sender As Object, e As EventArgs) Handles FQty3Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc3Box.Value = FQty3Box.Value * FPrice3Box.Value * FDays3Box.Value
            '--总金额
            FAmountLabel.Text = CInt(FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FPrice3Box_ValueChanged(sender As Object, e As EventArgs) Handles FPrice3Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc3Box.Value = FQty3Box.Value * FPrice3Box.Value * FDays3Box.Value
            '--总金额
            FAmountLabel.Text = CInt(FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
       
    End Sub

    Private Sub FDays3Box_ValueChanged(sender As Object, e As EventArgs) Handles FDays3Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc3Box.Value = FQty3Box.Value * FPrice3Box.Value * FDays3Box.Value
            '--总金额
            FAmountLabel.Text = CInt(FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
        
    End Sub

    Private Sub FAcc3Box_ValueChanged(sender As Object, e As EventArgs) Handles FAcc3Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc3Box.Value = FQty3Box.Value * FPrice3Box.Value * FDays3Box.Value
            '--总金额
            FAmountLabel.Text = CInt(FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
       
    End Sub

    Private Sub FQty4Box_ValueChanged(sender As Object, e As EventArgs) Handles FQty4Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc4Box.Value = FQty4Box.Value * FPrice4Box.Value * FDays4Box.Value
            '--总金额
            FAmountLabel.Text = CInt(FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
        
    End Sub

    Private Sub FPrice4Box_ValueChanged(sender As Object, e As EventArgs) Handles FPrice4Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc4Box.Value = FQty4Box.Value * FPrice4Box.Value * FDays4Box.Value
            '--总金额
            FAmountLabel.Text = CInt(FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
       
    End Sub

    Private Sub FDays4Box_ValueChanged(sender As Object, e As EventArgs) Handles FDays4Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc4Box.Value = FQty4Box.Value * FPrice4Box.Value * FDays4Box.Value
            '--总金额
            FAmountLabel.Text = CInt(FAcc1Box.Value + FAcc2Box.Value + FAcc3Box.Value + FAcc4Box.Value)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception

        End Try
       
    End Sub
#End Region

#Region "保存单据"
    Private Sub SaveBill()
        '---检查必录数据
        If FDateBox.Value = Nothing Then
            MsgBox("日期必须填写!")
            Return
        End If
        If FNameBox.Text = String.Empty Then
            MsgBox("交款单位必须填写!")
            Return
        End If
        If FItem1Box.Text.Trim = String.Empty Then
            MsgBox("第一行分录不能为空!")
            Return
        End If
        If FSDate1Box.Value = Nothing Or FEDate1Box.Value = Nothing Then
            MsgBox("第一行收费区间不能为空!")
            Return
        End If
        If FQty1Box.Value = 0 Then
            MsgBox("第一行平米数不能为空!")
            Return
        End If
        If FPrice1Box.Value = 0 Then
            MsgBox("第一行单价不能为空!")
            Return
        End If
        If FAcc1Box.Value = 0 Then
            MsgBox("第一行金额不正确!")
            Return
        End If

        '--第二行
        If FItem2Box.Text.Trim <> String.Empty Then
            If FSDate2Box.Value = Nothing Or FEDate2Box.Value = Nothing Then
                MsgBox("第二行收费区间不能为空!")
                Return
            End If
            If FQty2Box.Value = 0 Then
                MsgBox("第二行平米数不能为空!")
                Return
            End If
            If FPrice2Box.Value = 0 Then
                MsgBox("第二行单价不能为空!")
                Return
            End If
            If FAcc2Box.Value = 0 Then
                MsgBox("第二行金额不正确!")
                Return
            End If
        End If

        '--第三行
        If FItem3Box.Text.Trim <> String.Empty Then
            If FSDate3Box.Value = Nothing Or FEDate3Box.Value = Nothing Then
                MsgBox("第三行收费区间不能为空!")
                Return
            End If
            If FQty3Box.Value = 0 Then
                MsgBox("第三行平米数不能为空!")
                Return
            End If
            If FPrice3Box.Value = 0 Then
                MsgBox("第三行单价不能为空!")
                Return
            End If
            If FAcc3Box.Value = 0 Then
                MsgBox("第三行金额不正确!")
                Return
            End If
        End If
        '--第四行
        If FItem4Box.Text.Trim <> String.Empty Then
            If FSDate4Box.Value = Nothing Or FEDate4Box.Value = Nothing Then
                MsgBox("第四行收费区间不能为空!")
                Return
            End If
            If FQty4Box.Value = 0 Then
                MsgBox("第四行平米数不能为空!")
                Return
            End If
            If FPrice4Box.Value = 0 Then
                MsgBox("第四行单价不能为空!")
                Return
            End If
            If FAcc4Box.Value = 0 Then
                MsgBox("第四行金额不正确!")
                Return
            End If
        End If
        Try
            Dim ErrString As String = String.Empty
            FBinfo.FDate = FDateBox.Value
            If FBinfo Is Nothing Or FBinfo.id = Nothing Then
                '--新单据保存
                '-检查客户是否存在
                Dim s As Integer = FNameBox.FindStringExact(FNameBox.Text)
                If s < 0 Then
                    '--不存在,FCID写-1
                    FBinfo.FCid = -1
                    FBinfo.FName = FNameBox.Text
                    FBinfo.FCName = FCNameBox.Text
                Else
                    '--写FCID
                    FBinfo.FCid = FNameBox.SelectedValue
                    FBinfo.FName = FNameBox.Text
                    FBinfo.FCName = FCNameBox.Text
                End If
                '--组合结构体
                If FItem1Box.Text <> String.Empty Then
                    s = FItem1Box.FindStringExact(FItem1Box.Text)
                    If s >= 0 Then
                        '--找到相应ID,填写FITEMID
                        If FItem1Box.SelectedIndex <> s Then
                            FItem1Box.SelectedIndex = s
                        End If
                        FBinfo.FItem1 = FItem1Box.SelectedValue
                        FBinfo.FItemName1 = FItem1Box.Text.Trim
                    Else
                        '--FItemid写-1,直接写名称
                        FBinfo.FItem1 = -1
                        FBinfo.FItemName1 = FItem1Box.Text.Trim
                    End If
                    If FSDate1Box.Value = Nothing Or FEDate1Box.Value = Nothing Then
                        MsgBox("收费区间不能为空!")
                        Return
                    End If
                    FBinfo.FSDate1 = FSDate1Box.Value.Date
                    FBinfo.FEDate1 = FEDate1Box.Value.Date
                    If FQty1Box.Value = 0 Then
                        MsgBox("平米数不能为0")
                        Return
                    End If
                    If FPrice1Box.Value = 0 Then
                        MsgBox("元/天.平 不能为空")
                        Return
                    End If
                    If FDays1Box.Value = 0 Then
                        MsgBox("天数不能为空!")
                        Return
                    End If
                    FBinfo.FQty1 = FQty1Box.Value
                    FBinfo.FPrice1 = FPrice1Box.Value
                    FBinfo.FDays1 = FDays1Box.Value
                    FBinfo.FAcc1 = FAcc1Box.Value
                End If

                '-第二行
                If FItem2Box.Text <> String.Empty Then
                    s = FItem2Box.FindStringExact(FItem2Box.Text)
                    If s >= 0 Then
                        '--找到相应ID,填写FITEMID
                        If FItem2Box.SelectedIndex <> s Then
                            FItem2Box.SelectedIndex = s
                        End If
                        FBinfo.FItem2 = FItem2Box.SelectedValue
                        FBinfo.FItemName2 = FItem2Box.Text.Trim
                    Else
                        '--FItemid写-1,直接写名称
                        FBinfo.FItem2 = -1
                        FBinfo.FItemName2 = FItem2Box.Text.Trim
                    End If
                    If FSDate2Box.Value = Nothing Or FEDate2Box.Value = Nothing Then
                        MsgBox("收费区间不能为空!")
                        Return
                    End If
                    FBinfo.FSDate2 = FSDate2Box.Value.Date
                    FBinfo.FEDate2 = FEDate2Box.Value.Date
                    If FQty2Box.Value = 0 Then
                        MsgBox("平米数不能为0")
                        Return
                    End If
                    If FPrice2Box.Value = 0 Then
                        MsgBox("元/天.平 不能为空")
                        Return
                    End If
                    If FDays2Box.Value = 0 Then
                        MsgBox("天数不能为空!")
                        Return
                    End If
                    FBinfo.FQty2 = FQty2Box.Value
                    FBinfo.FPrice2 = FPrice2Box.Value
                    FBinfo.FDays2 = FDays2Box.Value
                    FBinfo.FAcc2 = FAcc2Box.Value
                End If

                '-第三行
                If FItem3Box.Text <> String.Empty Then
                    s = FItem3Box.FindStringExact(FItem3Box.Text)
                    If s >= 0 Then
                        '--找到相应ID,填写FITEMID
                        If FItem3Box.SelectedIndex <> s Then
                            FItem3Box.SelectedIndex = s
                        End If
                        FBinfo.FItem3 = FItem3Box.SelectedValue
                        FBinfo.FItemName3 = FItem3Box.Text.Trim
                    Else
                        '--FItemid写-1,直接写名称
                        FBinfo.FItem3 = -1
                        FBinfo.FItemName3 = FItem3Box.Text.Trim
                    End If
                    If FSDate3Box.Value = Nothing Or FEDate3Box.Value = Nothing Then
                        MsgBox("收费区间不能为空!")
                        Return
                    End If
                    FBinfo.FSDate3 = FSDate3Box.Value.Date
                    FBinfo.FEDate3 = FEDate3Box.Value.Date
                    If FQty3Box.Value = 0 Then
                        MsgBox("平米数不能为0")
                        Return
                    End If
                    If FPrice3Box.Value = 0 Then
                        MsgBox("元/天.平 不能为空")
                        Return
                    End If
                    If FDays3Box.Value = 0 Then
                        MsgBox("天数不能为空!")
                        Return
                    End If
                    FBinfo.FQty3 = FQty3Box.Value
                    FBinfo.FPrice3 = FPrice3Box.Value
                    FBinfo.FDays3 = FDays3Box.Value
                    FBinfo.FAcc3 = FAcc3Box.Value
                End If

                '-第四行
                If FItem4Box.Text <> String.Empty Then
                    s = FItem4Box.FindStringExact(FItem4Box.Text)
                    If s >= 0 Then
                        '--找到相应ID,填写FITEMID
                        If FItem4Box.SelectedIndex <> s Then
                            FItem4Box.SelectedIndex = s
                        End If
                        FBinfo.FItem4 = FItem4Box.SelectedValue
                        FBinfo.FItemName4 = FItem4Box.Text.Trim
                    Else
                        '--FItemid写-1,直接写名称
                        FBinfo.FItem4 = -1
                        FBinfo.FItemName4 = FItem4Box.Text.Trim
                    End If
                    If FSDate4Box.Value = Nothing Or FEDate4Box.Value = Nothing Then
                        MsgBox("收费区间不能为空!")
                        Return
                    End If
                    FBinfo.FSDate4 = FSDate4Box.Value.Date
                    FBinfo.FEDate4 = FEDate4Box.Value.Date
                    If FQty4Box.Value = 0 Then
                        MsgBox("平米数不能为0")
                        Return
                    End If
                    If FPrice4Box.Value = 0 Then
                        MsgBox("元/天.平 不能为空")
                        Return
                    End If
                    If FDays4Box.Value = 0 Then
                        MsgBox("天数不能为空!")
                        Return
                    End If
                    FBinfo.FQty4 = FQty4Box.Value
                    FBinfo.FPrice4 = FPrice4Box.Value
                    FBinfo.FDays4 = FDays4Box.Value
                    FBinfo.FAcc4 = FAcc4Box.Value
                End If

                FBinfo.FAmount = CDbl(FAmountLabel.Text)
                FBinfo.FUid = UInfo.id
                FBinfo.FUName = UInfo.FRName
                If FOpenType = "Modify" Then
                    '--修改
                    If SControl._BILL_Prop_ModifyBill(UInfo.FSession, FBinfo, ErrString) = False Then
                        MsgBox(ErrString)
                        Return
                    End If
                Else
                    If SControl._Bill_Prop_SaveBill(UInfo.FSession, FBinfo, ErrString) = False Then
                        MsgBox(ErrString)
                        Return
                    End If
                End If
                
                CHGControls(False)
                '--取单号和验证码
                If FBinfo.FVerifyCode Is Nothing Or FBinfo.FBillNo Is Nothing Then
                    MsgBox("取单据号码和验证码失败!未知错误")
                    Return
                End If
                '-写单号和验证码
                FBillNoBox.Text = FBinfo.FBillNo
                FVerifyCodeBox.Text = FBinfo.FVerifyCode
                FSaveBox.Enabled = False
                If SControl._User_CheckAuth(UInfo.FSession, "BILL", "FPBILLVERIFYMY", "") Then
                    FSaveBox.Enabled = True
                    FSaveBox.Image = My.Resources.money
                    FSaveBox.Text = "收费"
                End If
            ElseIf FBinfo.FVid = Nothing And FBinfo.id > 0 Then
                '--审核
                FBinfo.FVid = UInfo.id
                FBinfo.FVName = UInfo.FRName
                If SControl._Bill_Prop_SaveBill(UInfo.FSession, FBinfo, ErrString) = False Then
                    MsgBox(ErrString)
                    Return
                End If
                FPNameBox.Text = FBinfo.FVName
                MsgBox("收费成功!")
                FSaveBox.Enabled = False
                FPrintBox.Enabled = True
                Return
            Else
                MsgBox("参数错误!")
                Return
            End If
        Catch ex As Exception
            MsgBox(String.Format("保存单据时出现错误!{0}错误信息:{1}", vbCrLf, ex.Message))
        End Try
    End Sub
#End Region

#Region "客户名称框文本改变和选择改变事件"
    Private Sub FNameBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FNameBox.SelectedIndexChanged
        '--选择改变
        If FOpenType = "View" Then
            Return
        End If
        FCNameBox.SelectedIndex = FNameBox.SelectedIndex
    End Sub

    Private Sub FNameBox_TextChanged(sender As Object, e As EventArgs) Handles FNameBox.TextChanged

        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim ds As New DataSet
            '--搜索字符是否已存在于组合框里
            Dim s As Integer = FNameBox.FindStringExact(FNameBox.Text)

            If s >= 0 Then
                '--如果当前选择的不是此项则自动选择
                If FNameBox.SelectedIndex <> s Then
                    FNameBox.SelectedIndex = s
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "读取单据信息"
    Private Function GetBillInfo() As Boolean
        FBinfo = New BServer.FBillProperty
        Try
            Dim ErrString As String = String.Empty
            If SControl._BILL_Prop_GetBillInfo(UInfo.FSession, FBid, "", FBinfo, ErrString) = False Then
                MsgBox(ErrString)
                Return False
            End If
            GetItemList()
            FItem1Box.SelectedValue = FBinfo.FItem1
            FItem2Box.SelectedValue = FBinfo.FItem2
            FItem3Box.SelectedValue = FBinfo.FItem3
            FItem4Box.SelectedValue = FBinfo.FItem4

            FDateBox.Value = FBinfo.FDate
            FDateBox.Enabled = False
            FNameBox.Text = FBinfo.FName
            FNameBox.Enabled = False
            FCNameBox.Text = FBinfo.FCName
            FCNameBox.Enabled = False
            FBillNoBox.Text = FBinfo.FBillNo
            FVerifyCodeBox.Text = FBinfo.FVerifyCode

            FItem1Box.Enabled = False
            FQty1Box.Value = FBinfo.FQty1
            FQty1Box.Enabled = False
            FPrice1Box.Value = FBinfo.FPrice1
            FPrice1Box.Enabled = False
            FDays1Box.Value = FBinfo.FDays1
            FDays1Box.Enabled = False
            FAcc1Box.Value = FBinfo.FAcc1
            FAcc1Box.Enabled = False


            FItem2Box.Enabled = False
            FQty2Box.Value = FBinfo.FQty2
            FQty2Box.Enabled = False
            FPrice2Box.Value = FBinfo.FPrice2
            FPrice2Box.Enabled = False
            FDays2Box.Value = FBinfo.FDays2
            FDays2Box.Enabled = False
            FAcc2Box.Value = FBinfo.FAcc2
            FAcc2Box.Enabled = False


            FItem3Box.Enabled = False
            FQty3Box.Value = FBinfo.FQty3
            FQty3Box.Enabled = False
            FPrice3Box.Value = FBinfo.FPrice3
            FPrice3Box.Enabled = False
            FDays3Box.Value = FBinfo.FDays3
            FDays3Box.Enabled = False
            FAcc3Box.Value = FBinfo.FAcc3
            FAcc3Box.Enabled = False


            FItem4Box.Enabled = False
            FQty4Box.Value = FBinfo.FQty4
            FQty4Box.Enabled = False
            FPrice4Box.Value = FBinfo.FPrice4
            FPrice4Box.Enabled = False
            FDays4Box.Value = FBinfo.FDays4
            FDays4Box.Enabled = False
            FAcc4Box.Value = FBinfo.FAcc4
            FAcc4Box.Enabled = False

            FSDate1Box.Value = FBinfo.FSDate1
            FSDate1Box.Enabled = False
            FEDate1Box.Value = FBinfo.FEDate1
            FEDate1Box.Enabled = False

            FSDate2Box.Value = FBinfo.FSDate2
            FSDate2Box.Enabled = False
            FEDate2Box.Value = FBinfo.FEDate2
            FEDate2Box.Enabled = False

            FSDate3Box.Value = FBinfo.FSDate3
            FSDate3Box.Enabled = False
            FEDate3Box.Value = FBinfo.FEDate3
            FEDate3Box.Enabled = False

            FSDate4Box.Value = FBinfo.FSDate4
            FSDate4Box.Enabled = False
            FEDate4Box.Value = FBinfo.FEDate4
            FEDate4Box.Enabled = False


            FAmountLabel.Text = FBinfo.FAmount
            FAmountBigLabel.Text = FControl.MoneyToUpper(FBinfo.FAmount)

            FUNameBox.Text = FBinfo.FUName
            FPNameBox.Text = FBinfo.FVName

            Label1.Text = "打印次数:" & FBinfo.FPCount
            Return True
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        End Try
    End Function
#End Region
#Region "设置控件状态"
    Public Sub CHGControls(ByVal FStat As Boolean)
        FDateBox.Enabled = FStat
        If FOpenType <> "Modify" Then
            FNameBox.Enabled = FStat
            FCNameBox.Enabled = FStat
        End If
        

        FItem1Box.Enabled = FStat
        FQty1Box.Enabled = FStat
        FPrice1Box.Enabled = FStat

        FItem2Box.Enabled = FStat
        FQty2Box.Enabled = FStat
        FPrice2Box.Enabled = FStat

        FItem3Box.Enabled = FStat
        FQty3Box.Enabled = FStat
        FPrice3Box.Enabled = FStat

        FItem4Box.Enabled = FStat
        FQty4Box.Enabled = FStat
        FPrice4Box.Enabled = FStat


        FSDate1Box.Enabled = FStat
        FEDate1Box.Enabled = FStat

        FSDate2Box.Enabled = FStat
        FEDate2Box.Enabled = FStat

        FSDate3Box.Enabled = FStat
        FEDate3Box.Enabled = FStat

        FSDate4Box.Enabled = FStat
        FEDate4Box.Enabled = FStat
    End Sub

#End Region
End Class
